package asteroids.statements;


import java.util.*;

import asteroids.*;
import asteroids.types.Type;
import be.kuleuven.cs.som.annotate.*;

public abstract class Statement {
	
	private int lineNumber;
	private int columnNumber;
	
	protected Statement(int line, int column) {
		this.lineNumber = line;
		this.columnNumber = column;
	}
	
	@Basic
	public int getLine() {
		return lineNumber;
	}
	
	@Basic
	public int getColumn() {
		return columnNumber;
	}

	public int getTotalNbOfStatements() {
		int result = 0;
		for(int i=1; i <= getNbOfStatements(); i++){
			if(this instanceof ComposedStatement) {
				Statement nextStatement = ((ComposedStatement) this).getStatementAt(i);
				result = result + nextStatement.getTotalNbOfStatements();
			}
			result++;
		}
		return result;
	}
	
	public List<Statement> getAllStatements() {
		List <Statement> statements = new ArrayList<Statement>();
		for(int i=1; i <= getNbOfStatements(); i++){
			if(!statements.contains(this))
				statements.add(this);
			if(this instanceof ComposedStatement) {
				Statement nextStatement = ((ComposedStatement) this).getStatementAt(i);
				statements.addAll(nextStatement.getStatements());
			}
		}
		return statements;
	}
	
	public List<Statement> getStatements() {
		List <Statement> statements = new ArrayList<Statement>();
		for(int i=1; i <= getNbOfStatements(); i++){
			statements.add(this.getStatementAt(i));
		}
		return statements;
	}
	
	public abstract boolean hasActionStatement();
	
	public abstract List<String> getTypeCheckErrors(List<String> typeErrors, Map<String, Type> map);
	
	public abstract boolean hasSubstatement();
	
	public abstract Statement getStatementAt(int index) throws IndexOutOfBoundsException;

	public abstract void execute(Ship ship);
	
	public abstract boolean hasAsSubStatement(Statement statement);
	
	public abstract int getNbOfStatements();
	
}

